﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL_Class
{
    public class BaiViet
    {
        NLLDataContext db = new NLLDataContext();
        public string AddNewArticle(Article arti)
        {
            string result = string.Empty;
            try{
            var zz = db.sp_Article_AddNew(arti.MenuID, arti.Title, arti.ThumbImage, arti.Description, arti.Content, arti.CreateDate, arti.IsSilde, arti.IsFrontPage, arti.AuthorID, arti.MetaTitle, arti.MetaDescription, arti.MetaKeywords, arti.MetaRobots, arti.MetaAuthor);

            result = "Thêm mới thành công";
        }
        catch (Exception ex)
        {
            throw ex;
        }

            return result;
        }
        public string Updatearticle(Article arti)
        {
            string result = string.Empty;
            try{
            var a = db.sp_Article_Update(arti.ID, arti.MenuID, arti.Title, arti.ThumbImage, arti.Description, arti.Content, arti.CreateDate, arti.IsSilde, arti.IsFrontPage, arti.AuthorID, arti.MetaTitle, arti.MetaDescription, arti.MetaKeywords, arti.MetaRobots, arti.MetaAuthor);
            result = "Chỉnh Sửa thành công";
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public void DeleteArticle(int id)
        {
            try{
            var a = db.sp_Article_Delete(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public IEnumerable<view_UI_ALLArticle> Search(string keyword) {
             IEnumerable <view_UI_ALLArticle > kequa = from a in db.view_UI_ALLArticles 
                                                              where a.Title.Contains(keyword) || a.Description.Contains(keyword) || a.Content.Contains(keyword)
                                                              select a;
             return kequa;
        }
    }
}
